<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body ng-controller="Ctrl">
<form name="userForm">
    Name:
    <!--
        updateOn: 什么事件触发后更新 model, 默认值: 'default', 还可以多个并存, 用空格分开  'default blur'
        debounce: 多少毫秒后更新 model. 可以是值类型, 也可以是对象. 如: debounce: {'default': 500, 'blur': 0}
        allowInvalid: model的值不需要验证
        getterSetter: model是否是通过function获取值的
        timezone: 时区(UTC等), input标签的type为 date time 时有用
    -->
    <input type="text" name="userName"
           ng-model="user.name"
           ng-model-options="{getterSetter: true, allowInvalid: true}"/>
</form>
<pre>user.name = <span ng-bind="user.name"></span></pre>
<script src="../../../../../../../bower_components/angular/angular.js"></script>
<script>
    var app = angular.module('app', []);
    app.controller('Ctrl', function ($scope) {
        var _name = 'Jim'
        $scope.user = {
            name: function (nv) {

                console.log(nv);
                return arguments.length ? (_name = nv) : _name;
            }
        };
//        $scope.cancel = function (e) {
//            if (e.keyCode == 27) {
//                $scope.userForm.userName.$rollbackViewValue();
//            }
//        };
    });
</script>
</body>
</html>